package com.stone.design.mode.builder;

import lombok.Data;

/**
 * 触发消息BO（自定义建造者实现）
 *
 * @author Mr_wenpan@163.com 2021/07/14 22:03
 */
@Data
public class TriggerMessageParam<K> {

    /**
     * 查询数据所需的参数，比如你要从Redis里的某个list队列里获取数据，
     * 那么queryDataParam就是指代这个list的key
     */
    private K queryDataParam;

    /**
     * 消息发送的队列名称
     */
    private String queue;

    /**
     * 线程数量
     */
    private Integer taskCount;

    /**
     * 用户ID
     */
    private Long userId;

    public TriggerMessageParam() {

    }

    /**
     * 自己实现建造者
     *
     * @author Mr_wenpan@163.com 2021/7/17 12:06 上午
     */
    @Data
    public static class TriggerMessageParamBuilder<K> {

        private K queryDataParam;

        private String queue;

        private Integer taskCount;

        private Long userId;

        public TriggerMessageParamBuilder<K> queryDataParam(K queryDataParam) {
            this.queryDataParam = queryDataParam;
            return this;
        }

        public TriggerMessageParamBuilder<K> queue(String queue) {
            this.queue = queue;
            return this;
        }

        public TriggerMessageParamBuilder<K> taskCount(Integer taskCount) {
            this.taskCount = taskCount;
            return this;
        }

        public TriggerMessageParamBuilder<K> userId(Long userId) {
            this.userId = userId;
            return this;
        }

        public TriggerMessageParam<K> build() {
            TriggerMessageParam<K> messageParam = new TriggerMessageParam<>();
            messageParam.setQueryDataParam(getQueryDataParam());
            messageParam.setQueue(getQueue());
            messageParam.setTaskCount(getTaskCount());
            messageParam.setUserId(getUserId());
            return messageParam;
        }

    }

    public static <T> TriggerMessageParamBuilder<T> builder() {
        return new TriggerMessageParamBuilder<>();
    }
}
